<template>
	<slot :controller="controller" :store="store" :model="model">
		<AppBasisViewLayout :class="classNames" :openType="openType">
			<template #default>
				<div class="view-content__body__transfer">
					<slot
						name="ViewSource"
						:controller="controller"
						:store="store"
						:model="model"
						:actions="{ handleCtrlInit, handleCtrlAction, handleCtrlDestroy }"
					>
						<div class="view-content__body__transfer__left deexpview">
							<AppSplit
								v-model="split"
								class="app-vc-expbar"
								mode="horizontal"
								@move-end="handleSplitChange(model, split)"
							>
								<template #left>
									<div class="app-vc-expbar__left">
										<slot
											name="Sys_roleUsr0309683501MPickupView2treeexpbarTreeExpBar"
											:controller="controller"
											:store="store"
											:model="model"
											:actions="{
												handleCtrlInit,
												handleCtrlAction,
												handleCtrlDestroy,
											}"
										>
											<Sys_roleUsr0309683501MPickupView2treeexpbarTreeExpBar
												:openView="store.openView"
												:newView="store.newView"
												name="treeexpbar"
												v-bind="model.ctrlParams.Sys_roletreeexpbar"
												:context="store.context"
												:viewParams="store.viewParams"
												:closeView="store.closeView"
												:pLoadingHelper="store.loadingHelper"
												:pViewCtx="store.viewCtx"
												@ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
												@ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
												@ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"
											>
											</Sys_roleUsr0309683501MPickupView2treeexpbarTreeExpBar>
										</slot>
									</div>
								</template>
								<template #right>
									<div class="app-vc-expbar__body">
										<component
											v-if="store.navParam && store.navParam.navData"
											v-bind="model.ctrlParams.Sys_rolepickupviewpanel"
											name="pickupviewpanel"
											:is="
												Sys_roleUsr0309683501MPickupView2pickupviewpanelPickupViewPanel
											"
											:context="store.navParam.navData.context"
											:viewParams="store.navParam.navData.viewParams"
											:closeView="store.closeView"
											:pLoadingHelper="store.loadingHelper"
											:pViewCtx="store.viewCtx"
											@ctrl-init="(name:string, ability:any) => { handleCtrlInit(controller, name, ability) }"
											@ctrl-action="(name:string, action:any, data:any) => { handleCtrlAction(controller, name, action, data) }"
											@ctrl-destroy="(name:string, data:any) => { handleCtrlDestroy(controller, name, data) }"
										/>
									</div>
								</template>
							</AppSplit>
						</div>
					</slot>
					<slot
						name="ViewBottons"
						:controller="controller"
						:store="store"
						:model="model"
						:actions="{ handleMPickupViewPickButtonAction }"
					>
						<div class="view-content__body__transfer__center">
							<AppButton
								type="primary"
								@click="
									handleMPickupViewPickButtonAction(controller, 'toRight')
								"
								:disabled="
									store.selections.length >= store.tempSelections.length
								"
								><RightOutlined
							/></AppButton>
							<AppButton
								type="primary"
								@click="handleMPickupViewPickButtonAction(controller, 'toLeft')"
								:disabled="store.panelSelectedKeys.length === 0"
								><LeftOutlined
							/></AppButton>
							<AppButton
								type="primary"
								@click="
									handleMPickupViewPickButtonAction(controller, 'toAllRight')
								"
								><DoubleRightOutlined
							/></AppButton>
							<AppButton
								type="primary"
								@click="
									handleMPickupViewPickButtonAction(controller, 'toAllLeft')
								"
								:disabled="store.selections.length === 0"
								><DoubleLeftOutlined
							/></AppButton>
						</div>
					</slot>
					<slot
						name="ViewTarget"
						:controller="controller"
						:store="store"
						:model="model"
						:actions="{ handleMPickupViewAction }"
					>
						<div class="view-content__body__transfer__right">
							<div class="view-content__body__transfer__right__select">
								<template v-for="item in store.selections" :key="item.srfkey">
									<div
										:class="getPanelItemClass(item)"
										@click="
											handleMPickupViewAction(
												controller,
												'panelItemClick',
												item
											)
										"
									>
										<span>{{ item.srfmajortext }}</span>
									</div>
								</template>
							</div>
						</div>
					</slot>
				</div>
			</template>
			<template #viewFooter>
				<slot
					name="ViewFooter"
					:controller="controller"
					:store="store"
					:model="model"
					:actions="{ handlePickupViewButtonAction }"
				>
					<div class="view-footer__buttons">
						<AppButton
							type="primary"
							:disabled="store.selections.length === 0"
							@click="handlePickupViewButtonAction(controller, 'confirm')"
							>确认</AppButton
						>
						<AppButton
							@click="handlePickupViewButtonAction(controller, 'cancel')"
							>取消</AppButton
						>
					</div>
				</slot>
			</template>
		</AppBasisViewLayout>
	</slot>
</template>
<script setup lang="ts">
// 基于template/src/views/{{appModules}}/{{pages@DEMPICKUPVIEW}}/{{spinalCase page.codeName}}-base.vue.hbs生成
import { AppBasisViewLayout } from '@components/layout/basis-view-layout';
import { AppSplit } from '@components/common/split';
import {
	RightOutlined,
	LeftOutlined,
	DoubleRightOutlined,
	DoubleLeftOutlined,
} from '@ant-design/icons-vue';
import Sys_roleUsr0309683501MPickupView2pickupviewpanelPickupViewPanel from '@widgets/sys-role/usr-0309683501-m-pickup-view-2-pickupviewpanel-pickup-view-panel/usr-0309683501-m-pickup-view-2-pickupviewpanel-pickup-view-panel.vue';
import Sys_roleUsr0309683501MPickupView2treeexpbarTreeExpBar from '@widgets/sys-role/usr-0309683501-m-pickup-view-2-treeexpbar-tree-exp-bar/usr-0309683501-m-pickup-view-2-treeexpbar-tree-exp-bar.vue';
import {
	useProps,
	useBasic,
	useAction,
	useController,
} from './sys-role-usr-0309683501-m-pickup-view-2-hook';
import {
	IEvent,
	IMPickupViewAbility,
	IMPickupView2Store,
	IParam,
	MPickupViewActionType,
} from '@/core';

const split = ref(0.15);

// 输入参数
const props = defineProps(useProps());

// 基础数据
const {
	model,
	getClassNames,
	useNavParamsBind,
	useEventBind,
	handleQuickSearch,
	handleToolbarItemClick,
	handleComponentAction,
	handleCtrlAction,
	handleCtrlInit,
	handleCtrlDestroy,
	handlePickupViewButtonAction,
	handleMPickupViewPickButtonAction,
	handleMPickupViewAction,
} = useBasic(props);

const emit = defineEmits<{
	(
		event: 'view-action',
		name: string,
		action: MPickupViewActionType,
		data: IParam[]
	): void;
	(event: 'view-init', name: string, data: IMPickupViewAbility): void;
	(event: 'view-mounted', name: string, data: IParam): void;
	(event: 'view-destroy', name: string, data: IParam): void;
}>();

const evt = useEventBind(emit);
const classNames = computed(() => {
	return getClassNames(props);
});

// 初始化控制器
const controller = useController(props, evt);

useNavParamsBind(controller, props);

const store: IMPickupView2Store = controller.getStore();

onMounted(() => {
	controller.viewMounted();
});

onUnmounted(() => {
	controller.viewDestroy();
});

const { getPanelItemClass, handleSplitChange } = useAction(controller);
</script>
